package com.droidwatcher.activity;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.widget.FrameLayout;

import com.droidwatcher.util.AXLog;
import com.droidwatcher2.R;



/**
 * Created by Administrator on 2018/4/9.
 */

public class LoginActivity extends  Activity implements  LoginCallback{
    FrameLayout fl_content ;
    private FragmentManager fragmentManager;
    LoginFragment loginFragment ;
    RegisterFragment registerFragment ;
    ModifyPwdFragment modifyPwdFragment ;
    FragmentTransaction transaction;

    Fragment chooseFrag ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        fl_content = (FrameLayout) findViewById(R.id.fl_content);
        fragmentManager = getFragmentManager();
        loginFragment = new LoginFragment();
        registerFragment = new RegisterFragment();
        modifyPwdFragment = new ModifyPwdFragment();
        transaction = fragmentManager.beginTransaction();
        transaction.add(R.id.fl_content, loginFragment).commit();
    }


    @Override
    public void toLogin() {
        transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.fl_content, loginFragment).commit();
        chooseFrag = loginFragment;
    }

    @Override
    public void toRegister() {
        transaction = fragmentManager.beginTransaction();
        AXLog.e("wzytest","run in toRegister");
        transaction.replace(R.id.fl_content, registerFragment).commit();
        chooseFrag  = registerFragment ;
    }

    @Override
    public void toFindpwd() {
        transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.fl_content,modifyPwdFragment).commit();
        chooseFrag = modifyPwdFragment ;
    }

    @Override
    public void onBackPressed() {
        if(chooseFrag!=loginFragment){
            toLogin();
        }else {
            super.onBackPressed();
        }
    }
}
